/*
 * File:   Vector.h
 * Author: Elevator
 *
 * Created on 12 Май 2013 г., 15:41
 */

#ifndef COMMON_VECTOR_H
#define COMMON_VECTOR_H

#include <vector>
#include <iterator>
#include <algorithm>
#include "Common/Collections/ICollection.h"
#include "Common/Collections/IIterator.h"
#include "Common/Collections/VectorIterator.h"

template<typename C>
class Vector : public ICollection<C> {
private:
	std::vector<C> _vector;

public:

	void Add( const C& item ) {
		_vector.push_back( item );
	}

	void Remove( const C& item ) {
		_vector.erase( std::find( _vector.begin( ), _vector.end( ), item ) );
	}

	void Remove( bool (*predicate )(const C& item ) ) {
		_vector.erase( std::find_if( _vector.begin( ), _vector.end( ), predicate ) );
	}

	bool Contains( const C& item ) {
		return std::find( _vector.begin( ), _vector.end( ), item ) != _vector.end( );
	}

	C Find( bool (*predicate )(const C& item ) ) {
		return *std::find_if( _vector.begin( ), _vector.end( ), predicate );
	}

	virtual IIterator<C>* GetIterator( ) const {
		return new VectorIterator<C > ( &_vector );
	}

	virtual std::vector<C> GetStdVector() const {
		std::vector<C> result;
		std::copy (_vector.begin(),_vector.end(),std::back_inserter(result));
		return result;
	}
};

#endif	/* VECTOR_H */

